<template>
  <view class="main">
    <view class="up">
      <UploadImage :limit="5" @upload="data => formData.image = data" />
    </view>
    <view class="title">
      <input type="text" placeholder="填写标题会有更多人赞哦~" v-model="formData.title" />
    </view>
    <view class="desc">
      <textarea class="ta" placeholder="添加正文" v-model="formData.content"></textarea>
    </view>
    <view class="btn-box1 w-100 dispaly-align-center">
      <view class="btn1 dispaly-align-center" @click="submit">发布</view>
    </view>
  </view>
</template>

<script setup lang="ts">
import UploadImage from '@/components/uploadImage/uploadImage.vue'
import { publishCommunity } from '@/api/home/home'
import { reactive } from 'vue'
import type { RequestPublishCommonityType } from '@/types/requstParm'

let formData = reactive<RequestPublishCommonityType>({
  user_id: 1,
  title: '',
  content: '',
  image: ''
})

// 图片上传
const upload = (urlJsonStr: string) => {
  console.log(urlJsonStr, 'urlJsonStr')
}

const submit = async () => {
  const res = await publishCommunity(formData)
  if (res.code == 0) {
    uni.showToast({
      title: res.msg as string,
      icon: 'none'
    })
    setTimeout(() => {
      uni.navigateBack()
    }, 1000)
  } else {
    uni.showToast({
      title: res.msg as string,
      icon: 'none'
    })
    return
  }
}

</script>
<style>
page {
  background-color: #fff;
}
</style>

<style lang="scss" scoped>
.main {
  padding: 50rpx;

  .title {
    border-bottom: 1rpx solid #DBDBDB;
    margin: 72rpx 0 24rpx 0;

    input {
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 28rpx;
      color: #C2C2C2;
      height: 71rpx;
    }
  }

  .desc {
    .ta {
      width: 100%;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 26rpx;
      color: #C2C2C2;
    }
  }
}

.btn-box1 {
  position: fixed;
  bottom: 97rpx;
  left: 0;
  right: 0;

  .btn1 {
    width: 523rpx;
    height: 84rpx;
    background: #008298;
    border-radius: 12rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: bold;
    font-size: 28rpx;
    color: #FFFFFF;
  }
}
</style>